import tkinter as tk
from tkinter import ttk
from pyopencl_z.ui.frame import TableFrame
from pyopencl_z.ui.notebook import AutoNotebook
from pyopencl_z.clinfo import Devices


class MainWindow(ttk.Frame):
    root = None

    def __init__(self,
                 width: int = 400,
                 height: int = 350,
                 **kwargs) -> None:
        if MainWindow.root is None:
            MainWindow.root = tk.Tk()
            MainWindow.root.title('PyOpenCL-Z')

        super().__init__(MainWindow.root, width=width, height=height, **kwargs)

        self.width = width
        self.height = height
        self.device_index = 0
        self.pad_x = 10
        self.pad_y = 10

        self.notebook = ttk.Notebook(self, width=width, height=height - self.pad_y)


        self.init_ui()

    def init_ui(self) -> None:
        self._init_device_page()

    def _init_device_page(self) -> None:
        table = TableFrame(self.notebook, width=self.width - self.pad_x * 2, title='device')
        device = Devices.get_device_info(self.device_index)

        table.add_line('Name', device.name)
        table.add_line('Platform', device.platform)
        table.add_line('Vendor', device.vendor)
        table.add_line('Type', device.type)
        table.pack()

        self.notebook.add(table, text='device')

    def pack(self, **kwargs) -> None:
        self.notebook.pack(padx=self.pad_x, pady=self.pad_y)

        super().pack(**kwargs)

    def mainloop(self, **kwargs) -> None:
        self.pack()

        MainWindow.root.mainloop()


if __name__ == '__main__':
    MainWindow().mainloop()
